package com.tutorial.advice;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 自定义增强类
 * className: MyAdvice
 * author: GXW
 * date: 2025/7/21 14:46:57
 * description: TODO 自定义增强类
 */
public class MyAdvice {
	public void beforeAdvice() {
		System.out.println("beforeAdvice ......");
	}

	public void afterReturningAdvice() {
		System.out.println("afterReturningAdvice ......");
	}

	public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
		// 环绕前
		System.out.println("环绕前通知");
		System.out.println(joinPoint.getArgs());// 获得目标方法的参数
		System.out.println(joinPoint.getTarget());// 获得目标对象
		System.out.println(joinPoint.getStaticPart());// 获得精确的切点表达式信息
		// 目标方法
		Object result = joinPoint.proceed();
		// 环绕后
		System.out.println("环绕后通知");
		return result;
	}

	public void afterThrowingAdvice(JoinPoint joinPoint,Throwable t) {
		System.out.println("目标方法抛出异常了，后置通知和环绕通知不再执行 ......");
		System.out.println("异常对象是：" + t + "异常信息是：" + t.getMessage());
	}

	public void afterAdvice(JoinPoint joinPoint) {
		// 获得目标方法的参数
		System.out.println(joinPoint.getArgs());
		// 获得目标对象
		System.out.println(joinPoint.getTarget());
		// 获得精确的切点表达式信息
		System.out.println(joinPoint.getStaticPart());
		System.out.println("afterAdvice ......");
	}
}
